use serde::Serialize;
use std::env;

#[derive(Debug, Clone, Serialize, Eq, PartialEq)]
pub enum Shell {
    Bash,
    Zsh,
    Fish,
    PowerShell,
    Cmd,
    Unknown,
    Tcsh,
    Csh,
    Ksh,
    Dash,
    Sh,
}

impl Shell {
    pub fn get_current_shell() -> Shell {
        if let Some(shell) = env::var("SHELL").ok() {
            match shell.to_lowercase().as_str() {
                s if s.ends_with("bash") => Shell::Bash,
                s if s.ends_with("zsh") => Shell::Zsh,
                s if s.ends_with("fish") => Shell::Fish,
                s if s.ends_with("tcsh") => Shell::Tcsh,
                s if s.ends_with("csh") => Shell::Csh,
                s if s.ends_with("ksh") => Shell::Ksh,
                s if s.ends_with("dash") => Shell::Dash,
                s if s.ends_with("sh") => Shell::Sh,
                s if s.contains("powershell") => Shell::PowerShell,
                s if s.contains("cmd") => Shell::Cmd,

                _ => Shell::Unknown,
            }
        } else {
            eprintln!("Warning: SHELL Not Found");
            Shell::Unknown
        }
    }
}
